home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / communic / pcmail / main / newseqno.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  2.0 KB  |  83 lines

  1. /*++
  2. /* NAME
  3. /*      newseqno 3
  4. /* SUMMARY
  5. /*      generate/extract sequence number for/from spool file
  6. /* PROJECT
  7. /*      pc-mail
  8. /* PACKAGE
  9. /*      general
  10. /* SYNOPSIS
  11. /*    unsigned seqno(s)
  12. /*    char *s;
  13. /*
  14. /*      unsigned newseqno()
  15. /* DESCRIPTION
  16. /*    seqno() verifies the format of a spool file name and extracts
  17. /*    its sequence number. A zero value is returned  if the validation
  18. /*    failed.
  19. /*
  20. /*      newseqno() deduces a new spool file sequence number by looking
  21. /*    at the names of all files in the spool directory.
  22. /* BUGS
  23. /*    A sequence file would be better both for performance, but not
  24. /*    for collision detection.
  25. /* AUTHOR(S)
  26. /*      W.Z. Venema
  27. /*      Eindhoven University of Technology
  28. /*      Department of Mathematics and Computer Science
  29. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  30. /* CREATION DATE
  31. /*      Sat Mar 28 18:10:53 GMT+1:00 1987
  32. /* LAST MODIFICATION
  33. /*    90/01/22 13:02:19
  34. /* VERSION/RELEASE
  35. /*    2.1
  36. /*--*/
  37.  
  38. #include "defs.h"
  39. #include "path.h"
  40. #include "ndir.h"
  41. #include "status.h"
  42.  
  43. /* newseqno - extract sequence number from existing spool file names */
  44.  
  45. public unsigned newseqno()
  46. {
  47.     register unsigned msgno = 0;
  48.     register struct direct *de;
  49.     register DIR *dp;
  50.     unsigned tmp = 0;
  51.  
  52.     /*
  53.      * We cannot terminate when directory access fails: live interrupts in
  54.      * the communications-port routines!
  55.      */
  56.  
  57.     while ((dp = opendir(maildir)) == 0)
  58.      /* void */ ;
  59.  
  60.     /* needs locking mechanism on multi-tasking operating systems */
  61.  
  62.     while (de = readdir(dp)) {
  63.     if ((tmp = seqno(de->d_name)) && (tmp > msgno))
  64.         msgno = tmp;
  65.     }
  66.     closedir(dp);
  67.     return (msgno + 1);
  68. }
  69.  
  70. /* seqno - validate format of spool file name and extract sequence number */
  71.  
  72. public unsigned seqno(s)
  73. char   *s;
  74. {
  75.     int     seq;
  76.     char    junk;
  77.  
  78.     if (strlen(s) == NAMELEN && sscanf(s + 1, "%u%c", &seq, &junk) == 1)
  79.     return (seq);
  80.     else
  81.     return (0);
  82. }
  83.